<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login_model extends CI_Model {

	public function do_login($param = false){
		if($param){
			$this->db->where('upper(trim(username))',strtoupper(trim($param['username'])));
			$this->db->where('upper(trim(password))',strtoupper(trim($param['password'])));
			return $this->db->get('users');
		}
	}

	public function generate_menu(){
		$menu = '';
		$mainmenu = $this->get_mainmenu()->result_array();
		foreach($mainmenu as $mainitem){
			if($mainitem['checked'] == 1){
				$menu .= '<li>';
				$menu .= '	<a class="ajax-link" href="'.base_url().index_page().'/'.$mainitem['link'].'"><i class="icon-edit"></i>&nbsp;<span class="hidden-tablet">'.$mainitem['nama_menu'].'</span></a>';
				$submenu = '';
				$subs = 0;
				// foreach($this->get_submenu($mainitem['id_main'])->result_array() as $subitem) {				
				// 	$submenu .= '<li><a href="'.base_url().index_page().'/'.$subitem['link_sub'].'">'.$subitem['nama_sub'].'</a></li>';
				// 	$subs++;
				// }
				// $menu .= ($subs>0) ? '<ul>'.$submenu.'</ul>' : '';
				$menu .= '</li>';
			}
		}
		return $menu;
	}

	public function get_mainmenu(){
		$id = $this->session->userdata['level'];
		return $this->db->query("
				SELECT a.*,(SELECT COUNT(*) FROM profile_menu b WHERE a.id_main = b.u_menu_id AND b.u_user_id = ".$id.") as checked
				FROM ref_menu a
			");
	}

	public function get_count($param=null){
		return $this->db->get($param);
	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */